<template>
  <view class="container">
    <uni-forms ref="form" :rules="{}">
      <uni-forms-item label="" name="">
        <uni-easyinput v-model="data.comment" type="textarea" autoHeight placeholder="请输入评论内容" />
      </uni-forms-item>
      <uni-forms-item label="" name="">
        <button type="primary" @click="postComment">发表</button>
      </uni-forms-item>
    </uni-forms>

  </view>
</template>

<script>
  export default {
    data() {
      return {
        data: {
          userId: null,
          foodId: null,
          comment: '',
          postDate: null
        }
      }
    },
    methods: {
      postComment() {
        this.data.postDate = new Date().toISOString()
        uni.request({
          url: 'http://localhost:8090/foodapp/comments/add',
          method: 'POST',
          data: this.data,
          success: res => {
            if (res.data.success) {
              uni.showToast({
                title: '成功',
                icon: 'none'
              });
            } else {
              uni.showToast({
                title: '失败',
                icon: 'none'
              });
            }
          },
          fail: () => {},
          complete: () => {}
        });
      }
    },
    onLoad(e) {
      this.data.foodId = e.foodid || 1
      this.data.userId = uni.getStorageSync('userInfo').id
      uni.onTabBarMidButtonTap(function(e) {
        console.log(e)

      })
    }
  }
</script>

<style>
  .container {
    padding: 20px;
    font-size: 14px;
    line-height: 24px;
  }
</style>